Corrected str_trunc() to pass correct 'left' and 'center' values to str_sub() when internal variable width...
is 0 or 1
#513
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Correction should close Issue #512 and #494.
Note: in my tests, the #494 pull request also fixes the issue. (However, the #494 fix is ~10% slower, likely due to the internal function definition, in the standard case where no 'left' or 'center' replacements of zero length occur. #494 is ~5% faster in the edge case corrected here, likely due to the internal function returning an empty sting directly instead of snipping to an empty string.)
Below is the summary of the issue:
Both cases happen because:
str_sub(string[too_long], -width..., -1))
becomes:
str_sub('characters', 0, -1))
which returns all 'characters' rather than the correct number
Example:
c('', 'a', 'aa', 'aaa', 'aaaa', 'aaaaaaa') |> str_trunc(3, 'center', "..")
Incorrectly returns:
[1] "" "a" "aa" "aaa" "a..aaaa" "a..aaaaaaa"
Rather than:
[1] "" "a" "aa" "aaa" "a.." "a.."